From a2d677ce9f34a50c37bca61beedf8946ca4c6b5e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 13 Jul 2016 19:20:47 +0300 Subject: [PATCH] Introduce `Context::host_triple` method --- src/cargo/ops/cargo_rustc/context.rs | 19 ++++++++++++------- src/cargo/ops/cargo_rustc/custom_build.rs | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index f73b9cada..53678eb5b 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -264,11 +264,21 @@ impl<'a, 'cfg> Context<'a, 'cfg> { } } + /// Return the host triple for this context + pub fn host_triple(&self) -> &str { + &self.config.rustc_info().host[..] + } + /// Return the target triple which this context is targeting. pub fn target_triple(&self) -> &str { &self.target_triple } + /// Requested (not actual) target for the build + pub fn requested_target(&self) -> Option<&str> { + self.build_config.requested_target.as_ref().map(|s| &s[..]) + } + /// Get the metadata for a target in a specific profile pub fn target_metadata(&self, unit: &Unit) -> Option { let metadata = unit.target.metadata(); @@ -600,8 +610,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> { None => return true, }; let (name, info) = match kind { - Kind::Host => (&self.config.rustc_info().host, &self.host_info), - Kind::Target => (&self.target_triple, &self.target_info), + Kind::Host => (self.host_triple(), &self.host_info), + Kind::Target => (self.target_triple(), &self.target_info), }; platform.matches(name, info.cfg.as_ref().map(|cfg| &cfg[..])) } @@ -632,11 +642,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> { /// Number of jobs specified for this build pub fn jobs(&self) -> u32 { self.build_config.jobs } - /// Requested (not actual) target for the build - pub fn requested_target(&self) -> Option<&str> { - self.build_config.requested_target.as_ref().map(|s| &s[..]) - } - pub fn lib_profile(&self, _pkg: &PackageId) -> &'a Profile { let (normal, test) = if self.build_config.release { (&self.profiles.release, &self.profiles.bench_deps) diff --git a/src/cargo/ops/cargo_rustc/custom_build.rs b/src/cargo/ops/cargo_rustc/custom_build.rs index c20eeca12..868f07a8f 100644 --- a/src/cargo/ops/cargo_rustc/custom_build.rs +++ b/src/cargo/ops/cargo_rustc/custom_build.rs @@ -106,13 +106,13 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) .env("CARGO_MANIFEST_DIR", unit.pkg.root()) .env("NUM_JOBS", &cx.jobs().to_string()) .env("TARGET", &match unit.kind { - Kind::Host => &cx.config.rustc_info().host[..], + Kind::Host => cx.host_triple(), Kind::Target => cx.target_triple(), }) .env("DEBUG", &profile.debuginfo.to_string()) .env("OPT_LEVEL", &profile.opt_level.to_string()) .env("PROFILE", if cx.build_config.release {"release"} else {"debug"}) - .env("HOST", &cx.config.rustc_info().host) + .env("HOST", cx.host_triple()) .env("RUSTC", &cx.config.rustc()) .env("RUSTDOC", &cx.config.rustdoc()); -- 2.30.2